package com.sec.android.app.myfiles.widget.listview;

import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.widget.GridView;

import com.sec.android.app.myfiles.R;
import com.sec.android.app.myfiles.decorator.AbsAdapterImpDecorator;
import com.sec.android.app.myfiles.decorator.gridview.GridViewDecorator;
import com.sec.android.app.myfiles.fragment.filelist.FileListAdapter;
import com.sec.android.app.myfiles.widget.listview.listdecorator.AbsListDecorator;

public class GridViewImp extends AbsListViewImp {
    GridViewDecorator mAdapterImpDecorator;

    public GridViewImp(Context context, View parentView, AbsListDecorator decorator) {
        super(context, parentView, decorator);
    }

    public GridViewImp(Context context, View parentView) {
        super(context, parentView);
    }

    @Override
    public void setAdapter(FileListAdapter adapter) {
        super.setAdapter(adapter);
        AbsAdapterImpDecorator decorator = new GridViewDecorator(mContext, mAdapter);
        mAdapterImpDecorator = (GridViewDecorator) decorator;
        adapter.setDecorator(decorator);
    }

    @Override
    protected int _getListLayoutId() {
        return R.id.grid_list;
    }

    @Override
    protected int _getItemLayoutId() {
        //Not used in Grace project because Grace is used GridListPinchDecorator. But add the grace feature just by way of exception.
        return R.layout.category_grid_item;
    }

    @Override
    protected int _getViewStubId() {
        return R.id.grid_list_stub;
    }

    @Override
    protected void _refreshLayout() {
        Resources res = mContext.getResources();

        int verticalSpacing = (int) res.getDimension(R.dimen.grid_view_spacing_vertical);
        int horizontalSpacing = (int) res.getDimension(R.dimen.grid_view_spacing_horizontal);
        int columnWidth = (int) res.getDimension(R.dimen.list_item_grid_size);
        int sidePadding = (int) res.getDimension(R.dimen.grid_view_padding_horizontal);
        int paddingTop = (int) res.getDimension(R.dimen.grid_view_padding_top);
        int paddingBottom = (int) res.getDimension(R.dimen.grid_view_padding_bottom);

        mAdapterImpDecorator.updateItemWidth(mContext);

        ((GridView) mListView).setColumnWidth(columnWidth);
        ((GridView) mListView).setVerticalSpacing(verticalSpacing);
        ((GridView) mListView).setHorizontalSpacing(horizontalSpacing);
        mListView.setPadding(sidePadding, paddingTop, sidePadding, paddingBottom);
    }
}
